package 力扣;

import java.util.ArrayList;
import java.util.List;

/**
 输入: 5
 输出:
 [
 [1],
 [1,1],
 [1,2,1],
 [1,3,3,1],
 [1,4,6,4,1]
 ]
 */

public class _118杨辉三角 {


    public List<List<Integer>> generate(int numRows) {
        int rowIndex=numRows-1;
        int[][] arr= new int[rowIndex+1][rowIndex+1];
        List<List<Integer>> ret = new ArrayList<List<Integer>>();
        for (int i = 0; i <=rowIndex; i++) {
            List<Integer> tem = new ArrayList<Integer>();
            for (int j = 0; j <=i; j++) {
                //起始项为1
                if(j==0) {
                    arr[i][j]=1;
                    //最后一项也为1
                }else if(i==j) {
                    arr[i][j]=1;
                }else {
                    arr[i][j]=arr[i-1][j-1]+arr[i-1][j];
                }
                tem.add(arr[i][j]);
            }
            ret.add(tem);
        }

        return ret;
    }
}
